package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.Consult;
import com.ruoyi.business.service.IConsultService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 咨询回复Controller
 * 
 * @author liwenjing
 * @date 2021-05-16
 */
@RestController
@RequestMapping("/business/consult")
public class ConsultController extends BaseController
{
    @Autowired
    private IConsultService consultService;

    /**
     * 查询咨询回复列表
     */
    @PreAuthorize("@ss.hasPermi('business:consult:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody Consult consult)
    {
        startPage();
        System.out.print(consult);
        List<Consult> list = consultService.selectConsultList(consult);
        return getDataTable(list);
    }

    /**
     * 导出咨询回复列表
     */
    @PreAuthorize("@ss.hasPermi('business:consult:export')")//导出按钮设置权限标识，一致时才可以调用到此方法
    @Log(title = "咨询回复", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Consult consult)
    {
        List<Consult> list = consultService.selectConsultList(consult);
        ExcelUtil<Consult> util = new ExcelUtil<Consult>(Consult.class);
        return util.exportExcel(list, "consult");
    }

    /**
     * 获取咨询回复详细信息
     */
//    @PreAuthorize("@ss.hasPermi('business:consult:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(consultService.selectConsultById(id));
    }

    /**
     * 新增咨询回复
     */
    @PreAuthorize("@ss.hasPermi('business:consult:add')")
    @Log(title = "咨询回复", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Consult consult)
    {
        return toAjax(consultService.insertConsult(consult));
    }

    /**
     * 修改咨询回复
     */
    @PreAuthorize("@ss.hasPermi('business:consult:edit')")
    @Log(title = "咨询回复", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Consult consult)
    {
        return toAjax(consultService.updateConsult(consult));
    }

    /**
     * 删除咨询回复
     */
    @PreAuthorize("@ss.hasPermi('business:consult:remove')")
    @Log(title = "咨询回复", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(consultService.deleteConsultByIds(ids));
    }

    @GetMapping("/getUndo")
    public Integer getUndo(Consult consult){
        System.out.print("查未读");
        System.out.print(consult);
        return consultService.getUndo(consult);
    }
}
